package com.mew.chess.core.game.shbz;

import com.mew.chess.core.common.handler.ChessHandlerMapCmdType;
import com.mew.chess.core.common.handler.ChessPlayAnnotation;
import com.mew.chess.core.common.handler.ChessPlayHandler;
import com.mew.chess.core.game.shbz.game.ShbzGameManager;
import com.mew.chess.core.game.shbz.game.ShbzRoomManager;
import com.mew.chess.core.game.shbz.game.ShbzTableManager;
import com.mew.chess.core.game.shbz.game.common.ArtilleryUtils;
import com.mew.chess.core.game.shbz.game.common.FishTableUtil;
import com.mew.chess.core.game.shbz.game.common.FishUserBO;
import com.mew.chess.core.game.shbz.game.message.ArtilleryDropMessage;
import com.mew.chess.core.game.shbz.game.message.FishCMDMapType;
import com.mew.chess.core.game.shbz.service.ShbzService;
import com.mew.common.rest.bo.GameSession;
import com.zebra.remoting.protocol.ZebraCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@ChessPlayAnnotation(ChessHandlerMapCmdType.ShbzDrop)
@Service
@Slf4j
public class ShbzArtiDropHandler implements ChessPlayHandler<ArtilleryDropMessage> {

    @Autowired
    private ArtilleryUtils artilleryUtils;

    @Override
    public void handle(ZebraCommand<ArtilleryDropMessage> command, GameSession gameSession) {
        long userId = command.getUserId();
        int roomId = gameSession.getRoomId();
        ShbzRoomManager manager = ShbzGameManager.getInstance().getController(roomId);
        ShbzTableManager table = manager.getTableByUserId(userId);
        FishUserBO fishUserBO = table.getOnlineUserMap().get(userId);

        ArtilleryDropMessage message = command.getRequest();
        long dorp = artilleryUtils.dorp(message.getArtillerys(),fishUserBO,ShbzGameManager.getInstance());

        message.setAwardNumber(dorp);
        message.setGoldNumber(fishUserBO.getGoldNumber());

        FishTableUtil.sendMsgByTable(table,message, FishCMDMapType.ArtilleryDropPushMessage.code(), 0);
    }


}
